Imports System.Xml
Imports System.IO
Imports System.Math

Public Class GenXML

   'Public Class MainClass
   '   Dim xmldoc As XmlDocument
   '   Dim xmlnode As XmlNode
   '   Dim xmlelem As XmlElement
   '   Dim xmlelem2 As XmlElement
   '   Dim xmltext As XmlText
   'End Class

   Dim xmldoc As XmlDocument
   Dim xmlnode As XmlNode
   Dim xmlelem As XmlElement
   Dim xmlelem2 As XmlElement
   Dim xmltext As XmlText

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

      Dim memory_stream As New MemoryStream()
      Dim writer As New XmlTextWriter(memory_stream, System.Text.Encoding.UTF8)

      writer.Formatting = Formatting.Indented
      writer.WriteStartDocument()

      writer.WriteStartElement("xmlTramites")

      For index As Integer = 1 To 100
         writer.WriteStartElement("Tramite")
         writer.WriteAttributeString("Orden", index.ToString())

         writer.WriteElementString("Numero", (index * Rnd()).ToString())
         writer.WriteElementString("Operacion", (index * Rnd()).ToString())

         writer.WriteEndElement() '' Tramite
      Next

      writer.WriteEndElement() '' xmlTramites
      writer.WriteEndDocument() '' Documento
      writer.Flush()

      Dim stream_reader As New StreamReader(memory_stream)

      memory_stream.Seek(0, SeekOrigin.Begin)
      Dim xml As String = stream_reader.ReadToEnd()
      Console.WriteLine(stream_reader.ReadToEnd())

      writer.Close()

      TextBox1.Text = xml

     
   End Sub

   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

      Dim memory_stream As New MemoryStream()
      Dim writer As New XmlTextWriter(memory_stream, System.Text.Encoding.UTF8)

      writer.Formatting = Formatting.Indented
      writer.WriteStartDocument()

      writer.WriteStartElement("xmlTramites")

      For index As Integer = 1 To 10
         writer.WriteStartElement("Tramite")
         writer.WriteAttributeString("Orden", index.ToString())
         writer.WriteAttributeString("Numero", (index * CType((100 * Rnd()), Integer)).ToString())
         writer.WriteAttributeString("Operacion", (index * CType((100 * Rnd()), Integer)).ToString())
         writer.WriteEndElement() '' Tramite
      Next

      writer.WriteEndElement() '' xmlTramites
      writer.WriteEndDocument() '' Documento
      writer.Flush()

      Dim stream_reader As New StreamReader(memory_stream)

      memory_stream.Seek(0, SeekOrigin.Begin)
      Dim xml As String = stream_reader.ReadToEnd()
      Console.WriteLine(stream_reader.ReadToEnd())

      writer.Close()

      TextBox1.Text = xml
   End Sub
End Class